package com.wangjiyuan.shiwupai.ui.activity.detail;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;
import android.webkit.WebResourceRequest;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.TextView;
import android.widget.Toast;

import com.wangjiyuan.shiwupai.R;

public class DetailActivity extends AppCompatActivity implements View.OnClickListener {
    private Toolbar toolbar;

    private WebView webView;
    private TextView share, news_keep;
    public static final String LINK = "link";
    private String link;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_detail);
        initData();
        initView();
    }

    private void initData() {
        Intent intent = getIntent();
        link = intent.getStringExtra(LINK);
    }

    private void initView() {
        toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        webView = (WebView) findViewById(R.id.web_view);
        share = (TextView) findViewById(R.id.share);
        share.setOnClickListener(this);
        news_keep = (TextView) findViewById(R.id.news_keep);
        news_keep.setOnClickListener(this);
        webView.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
                view.loadUrl(link);
                return super.shouldOverrideUrlLoading(view, request);
            }
        });
        webView.loadUrl(link);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case android.R.id.home:
                finish();
                break;
        }
        return super.onOptionsItemSelected(item);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.share:
                Toast.makeText(this, "分享", Toast.LENGTH_SHORT).show();
                break;
            case R.id.news_keep:
                Toast.makeText(this, "收藏", Toast.LENGTH_SHORT).show();
                break;
        }
    }
}
